<template>
    <a-form ref='formRef' :label-col='{span : 5}' :model='formData'>
        <a-form-item label='充值金额' name='amount'>
            <a-input type='number' v-model:value='formData.amount' />
        </a-form-item>
        <a-form-item label='赠送金额' name='rewardAmount'>
            <a-input type='number' v-model:value='formData.rewardAmount' />
        </a-form-item>
    </a-form>
</template>

<script lang="ts" setup>
    import { rechargeApi } from '@/api/recharge/Order';
    import { ref } from 'vue';


    const props = defineProps<{
        row? : any;
    }>()


    const formRef = ref()

    
    const formData = ref<any>({
        amount : '',
        rewardAmount : ''

    })

    // if(props.row) {
    //     for(let k in props.row) {
    //         if(k in formData.value) {
    //             formData.value[k] = props.row[k]
    //         }
    //     }

        

    // }

    async function submit() {
        let params  = await formRef.value.validate()

        params.userId = props.row.id
        

        params.amount = Number(params.amount || 0)
        params.rewardAmount = Number(params.rewardAmount || 0)
        return rechargeApi(params)
    }

    defineExpose({
        submit
    })
</script>